dim seltype
'seltype = inputbox("please input key char like 50",seltype,"50")
Dim doc
Set doc = application.ActiveDocument
GetUserLicence(doc)

main
msgbox "done"
sub main()
	on error resume next
	doc.currentunit=2 'th	
	'// select group
	doc.unselectall()
	dim ngroup	
	dim ncount:ncount=0
	set ncs = doc.netclasses("*")	
	
	dim ischeck
	for each nc in ncs
		on error resume next
		'msgbox nc.name
		ischeck =doc.activeView.DisplayControl.Global.Net("false",nc.name)
		if ischeck = true then
			doc.netclasses(nc.name).selected = true
			ncount= ncount+1
		end if
	next
	
	if ncount>1 then
		dim res:res = msgbox("multiple-choice,do you want to continue",4,"hint")
		if res = 7 then exit sub
	end if
	'// step1: create or clear userlayer
	Dim usrLyrObj
	dim nlyr:nlyr=doc.layercount
	dim i,ulyr
	for i=1 to nlyr
		
		ulyr = "L_" & i
		Set usrLyrObj = doc.FindUserLayer(ulyr)
		If usrLyrObj Is Nothing Then
			Set usrLyrObj = doc.SetupParameter.PutUserLayer(ulyr)
		Else
			doc.UserLayerGfxs(, ulyr).Delete
		End If
	next
	
	'// step2: copy trace & pad to userlayer
	dim fabGfxObj
	dim numPoints,pntsArr
	'copy trace
	dim sellyr
	dim pcbtraces,pcbtrace
	dim pcbtracewidth	
	set pcbtraces = doc.traces(1)
	for each pcbtrace in pcbtraces
		sellyr = pcbtrace.layer
		ulyr = "L_" & sellyr
		pcbtracewidth = pcbTrace.Geometry.LineWidth
		pntsArr = pcbTrace.Geometry.pointsarray
		numPoints = UBound(pntsArr, 2) + 1
		Set usrLyrObj = doc.FindUserLayer(ulyr)
		set fabGfxObj = doc.PutUserLayerGfx(usrLyrObj,pcbtracewidth,numPoints,pntsArr,False,Nothing,epcbUnitCurrent)
	next
	
	'// copy pstack
	dim pads_pstack,pad_pstack
	dim pinpads,pinpad
	dim pinpo,pinpos
	dim pntArr
	Set pstacks = doc.PadstackObjects(1,1) '1:pin | 2:via // 0:all |1:select
	for each pstack in pstacks
		selpskt = pstack.CurrentPadstack 
		sellyr = pstack.layer
		set pinpads = pstack.pads
		for each pinpad in pinpads
			set pinpos = pinpad.Geometries
			for each pinpo in pinpos
				pntArr = pinpo.PointsArray
				exit for
			next
			exit for
		next	
		numPoints = UBound(pntArr, 2) + 1			
		ulyr = "L_" & sellyr
		Set usrLyrObj = doc.FindUserLayer(ulyr)
		set fabGfxObj = doc.PutUserLayerGfx(usrLyrObj,1.0,numPoints,pntArr,true,Nothing,epcbUnitCurrent)
	next
end sub

sub select_net_group(netcls)
	doc.unselectall()
	doc.activeView.displaycontrol.global.MiscItems(29)=false 'Layer -> Planes -> Plane shapes & obstructs
	doc.activeView.displaycontrol.GeneralItems(9)=false 'epcbDCOtherHoles 
	doc.ActiveView.DisplayControl.Global.MiscItems(4)=false 'netclass
	
	dim NColorObject
	set NColorObject = application.utility.NewColorPattern 
	With NColorObject
				.red = 255
				.green =0
				.blue =0
				.index =0
				.outline=false
				.Transparent=false
	end With
	
	dim ncs,nc
	
	
	dim netall,netobj
	set netall = doc.nets(0)
	for each netobj in netall
		dim netname :netname = netobj.name
		if netobj.selected = false then			
			doc.activeView.DisplayControl.Global.Net("true",netname)=true
			set doc.ActiveView.DisplayControl.Global.NetColor("true",netname) = NColorObject
		else
			doc.activeView.DisplayControl.Global.Net("true",netname)=false
		end if
	next	
end sub

Private Function ValidateServer(docObj)
	Dim key, licenseServer, licenseToken
	key = docObj.Validate(0)
	Set licenseServer = CreateObject("MGCPCBAutomationLicensing.Application")
	licenseToken = licenseServer.GetToken(key)
	Set licenseServer = nothing
	Err.Clear
	docObj.Validate(licenseToken)
	If Err Then
	ValidateServer = 0
	Else
	ValidateServer = 1
	End If
End Function
sub GetUserLicence(docObj)
	If ValidateServer(docObj) = 0 Then
		msgbox "Server validation failed."
		exit sub
	End If	
end sub